import java.util.*;
import java.util.logging.Logger;
import java.io.*;

public class Main
{
	private static final Logger logger = Logger
			.getLogger(Logger.GLOBAL_LOGGER_NAME);

	public static void main(String[] args)
	{
		MyStack stack = new MyStack();
		try (BufferedReader fin = new BufferedReader(new FileReader("input.txt"));
				OutputStream fout = new FileOutputStream(new File("output.txt")))
		{
			String sCurrentLine;
			while ((sCurrentLine = fin.readLine()) != null)
			{
				System.out.println("Current line: " + sCurrentLine);
				for (char c : sCurrentLine.toCharArray())
				{
					stack.push(c);
					logger.info("Pushed " + c);
					System.out.println("Pushed " + c);
				}

				while (!stack.isEmpty())
				{
					logger.info("Writing " + stack.top());
					System.out.println("Writing " + stack.top());
					fout.write((byte) stack.pop2());
				}
				fout.write('\n');
			}
			System.out.println("We finished working");
			System.in.read();
		}
		catch (IOException | NoSuchElementException e)
		{
			logger.warning(e.toString());
			e.printStackTrace();
		}
	}
}
